/**
 * Author@ Cheng Feitian
 * Date: 2021-3-30
 * Description: 成员函数做友元
 */

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;
const int maxn = 1024;
class Building;

class GoodGay
{
private:
public:
    Building *building;
    GoodGay();
    ~GoodGay();

    void visit();  //让visit函数可以访问building中私有成员
    void visit2(); //让visit2函数不可以访问building中的私有成员
};

class Building
{   
    //告诉编译器 GoodGay类下的visit成员函数作为本类的好朋友，可以访问私有成员
    friend void GoodGay::visit();
private:
    string m_BedRoom;

public:
    string m_SittingRoom;

    Building();
    ~Building();
};

Building::Building()
{
    m_BedRoom = "卧室";
    m_SittingRoom = "客厅";
}

Building::~Building()
{
}

GoodGay::GoodGay()
{
    building = new Building;
}

GoodGay::~GoodGay()
{
}

void GoodGay::visit()
{
    cout << "visit 函数正在访问：" << building->m_SittingRoom << endl;
    cout << "visit 函数正在访问：" << building->m_BedRoom << endl;
}
void GoodGay::visit2()
{
    cout << "visit2 函数正在访问：" << building->m_SittingRoom << endl;
    // cout << "visit2 函数正在访问：" << building->m_BedRoom << endl;
}

void test01()
{
    GoodGay gg;
    gg.visit();
    gg.visit2();
}

int main()
{
    test01();
    return 0;
}
